<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ include file="admin_Header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
<title>Add Product</title>
</head>
<body>
<%
	if ((request.getParameter("productName") != null) &&
    	(request.getParameter("productUnit") != null) &&
		(request.getParameter("productQuantityPerUnit") != null))
	{
	    out.println("Adding product " + request.getParameter("productName"));
		try
		{
			String productName = request.getParameter("productName");
			String productUnit = request.getParameter("productUnit");
			Double productQuantityPerUnit = Double.parseDouble(request.getParameter("productQuantityPerUnit"));
			Product product = new Product();
			product.setProductName(productName);
			product.setProductUnit(productUnit);
			product.setProductQuantityPerUnit(productQuantityPerUnit);
			product.setProductImage(null);
			iproducts.AddProduct(product);
			Product verifyProduct = iproducts.FindProduct(product.getProductName(), product.getProductUnit(), product.getProductQuantityPerUnit());
			if ((verifyProduct.getProductName().equals(productName)) &&
				(verifyProduct.getProductQuantityPerUnit().equals(productQuantityPerUnit)) &&
				(verifyProduct.getProductUnit().equals(productUnit)))
			{
				out.println("\nProduct added successfully");
			}
			else
			{
				out.println("Something went wrong, please check");
			}
		}
		catch(Exception e)
		{
			throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
%>
<div data-role="page">
	<div data-role="header" align="center">
		<h1>Products Compare<br>Application</h1>
		<a href='#' class='ui-btn-left' data-icon='arrow-l' onclick="history.back(); return false">Back</a><a href="#admin_firstpage">Home</a>
	</div>
	
	<div data-role="content" align="center">
		<form action="admin_AddProduct.jsp" method="post">
			<div data-role="fieldcontain">
				<label for="productName">Product Name:</label>
				<input type="text" name="productName" id="productName" value=""/>
			</div>
			<div data-role="fieldcontain">
				<label for="productUnit">Unit:</label>
				<input type="text" name="productUnit" id="productUnit" value=""/>
			</div>
			<div data-role="fieldcontain">
				<label for="productQuantityPerUnit">Quantity Per Unit:</label>
				<input type="text" name="productQuantityPerUnit" id="productQuantityPerUnit" value=""/>
			</div>
			<div data-role="fieldcontain">
				<label for="productImage">Image:</label>
				<input type="File" name="productImage" id="productImage" value=""/>
			</div>
			<button type="submit" data-theme="e">Submit</button>
		</form>
	</div>
</div>
</body>
</html>